fix: httpjson callables to trace attempts (started, failed)#3300
Conversation
|
I think you can also remove a bunch of the I think they should pass with your PR. |
…eapis/sdk-platform-java into fix-httpjson-retry-metrics
| // the number of attempts varies. Here we just make sure that all of them except the last are | ||
| // considered as failed |
There was a problem hiding this comment.
qq, isn't the last one also considered a failed attempt? Why is the tracerAttemptsFailed != tracerAttempts?
Also, can we add the operationfailed == true check here as well?
There was a problem hiding this comment.
Why is the tracerAttemptsFailed != tracerAttempts?
I'm not sure and I agree they should be the same value since this test just fetches an exception until it can't retry anymore (retries exhausted).
There was a problem hiding this comment.
showcase has another tracer we can use to cross check TestApiTracer
lqiu96
left a comment
There was a problem hiding this comment.
LGTM. Added a few questions/ nits
| */ | ||
| public class TestApiTracer extends BaseApiTracer { | ||
|
|
||
| private final AtomicInteger tracerAttempts; |
There was a problem hiding this comment.
I think they can be called just attempts, same for the fields below.
There was a problem hiding this comment.
renamed to attemptsStarted, removed the tracer prefix from all fields
| tracerOperationFailed, | ||
| tracerFailedRetriesExhausted); | ||
|
|
||
| public AtomicInteger getTracerAttempts() { |
There was a problem hiding this comment.
I think it's better to get the tracer instance, and use the getters from the tracer in unit tests.
| * exhausted. | ||
| */ | ||
| public class TestApiTracerFactory implements ApiTracerFactory { | ||
| private final AtomicInteger tracerAttempts = new AtomicInteger(); |
There was a problem hiding this comment.
These can be initialized within the tracer for better encapsulation.
There was a problem hiding this comment.
I'd like to initialize them in the tracer itself. However the clients only expect tracer factories, so there is no way to have control over how the actual tracers are instantiated.
I'll double check on this.
There was a problem hiding this comment.
Ah nvm, I realized that accessing the ApiTracer instance should be enough.
| } | ||
|
|
||
| @Override | ||
| public void attemptStarted(int attemptNumber) { |
There was a problem hiding this comment.
There was a problem hiding this comment.
I like the idea of a test tracer in general. On the other hand, we should only implement what is needed for our use cases, so that we have lower chance to run into issues that are not related to our PR. For example, maybe we don't need to implement attemptFailedRetriesExhausted.
There was a problem hiding this comment.
@lqiu96 figured that the retries exhausted event records the missing failed attempt in our tests:
It looks like attempt_count is recorded when this is called:
. This seems like the number recorded in Otel should be correct.
I'm guessing your TestApiTracer would need to increment the attemptCount when attemptFailedRetriesExhausted is called as well to match behavior.
I'll keep this implementation and its retries exhausted flag.
| * Test tracer that keeps count of different events. See {@link TestApiTracerFactory} for more | ||
| * details. | ||
| */ | ||
| public class TestApiTracer extends BaseApiTracer { |
There was a problem hiding this comment.
We should use the interface ApiTracer instead.
This reverts commit e57b4db.
|
FYI @diegomarquezp |
|
|
|
From @lqiu96 (thanks!):
This means that the tests removed in 065b01f were actually expected behavior and is due to the way we set up the tests. |



Fixes #2503
Approach
This PR uses the approach suggested by the same bug.
Confirmation that it works
The confirmation that it works is in the modified tests (e.g.
retry()). When using the proposed test version against the version ofHttpJsonCallableFactoryfrom the main branch, it will fail because it will not record attempts started or failed whatsoever:The image above shows all tests having failed when using the production files from
main, implying that no tracer attempts are recorded for any of the tests.